$(document).ready( function(){
    datepickerGain();
    graphics();
    search();
    searchInvoiceDate();

})
function datepickerGain()
{
    $('#startDate,#endDate').datepicker({
        dateFormat: 'yy-mm-dd'
    });
    $('#startDate,#endDate').click(function(){
        $('#ui-datepicker-div').css('z-index', 2);
    });
}

function graphics()
{
    $(function(){
        /** This code runs when everything has been loaded on the page */
        /* Inline sparklines take their values from the contents of the tag */
        $('.inlinesparkline').sparkline(); 
        /* Sparklines can also take their values from the first argument 
        passed to the sparkline() function */
        var myvalues = [10,8,5,7,4,4,1];
        $('.dynamicsparkline').sparkline(myvalues);
        /* The second argument gives options such as chart type */
        $('.dynamicbar').sparkline(myvalues, {
            type:'bar', 
            barColor: 'green'
        } );
        /* Use 'html' instead of an array of values to pass options 
        to a sparkline with data in the tag */
        $('.inlinebar').sparkline('html', {
            type:'bar', 
            barColor: 'red'
        } );
        
        $("#sparkline").sparkline([8,4,2],{
            type:'pie',
            width: '225',
            height: '225'
        });
        
        var costo = $("#graphVal").val();
        $("#barsparkline").sparkline([costo,0], {
            type: 'bar',
            zeroAxis: false,
            barColor: '#ff00ff',
            negBarColor: '#f04040 ',
            zeroColor: '#ffffff',
            height: '250',
            barWidth: 26
        });
        
        
        
        
    
    });
}

function search()
{
    $('#searchEvent').on('change',function(){
        var valEvent = $(this).val();
        $.post(ajaxSearchEventReport,{
            value : valEvent
        },function(data){
            $('#listEvent').html(data);
        }) ;
    });
    
    $('#searchClient').on('change',function(){
        var valClient = $(this).val();
        $.post(ajaxSearchClientReport,{
            value : valClient
        },function(data){
            $('#listClient').html(data);
        }) ;
    });
    
    $('#searchGain').on('click',function(){
        var startDate = $('#startDate').val();
        var endDate = $('#endDate').val();
        $.post(ajaxSearchGainReport,{
            fechaIni : startDate,
            fechaFin : endDate
        },function(data){
            $('#listGain').html(data);
            graphics();
//            reporteTotal();
        }) ;
    });
    
    
}
function reporteTotal()
{ 
    var total = 0;
    $('.total').each(function(){
        total += $(this).val();
    });
    $('#totalFinal').html(total);
}

function searchInvoiceDate()
{
    $('#searchInvoiceDate').on('click', function(){
        var dateIni = $('#diaIni').val();
        var dateFin = $('#diaFin').val();
        $.post(axInvoiceDate,{
            diaIni: dateIni, 
            diaFin : dateFin
        },
        function(data)
        {
            $('#listInvoice').html(data),
            graphics();
        })
    });
}